<?php

namespace App\Http\Controllers\Test;

use App\Http\Controllers\Controller;
use App\Models\Backend\System\Student;
use App\Models\Backend\System\User;
use App\Models\Mobile\MobileStudent;
use Illuminate\Support\Facades\Auth;

class UserController extends Controller
{
    /**
     * 切换用户
     */
    public function switchUser($user_id)
    {
        $user = User::where('user_id', $user_id)->first();
        if ($user) {
            Auth::login($user);
            return redirect()->route('homes');
//            return redirect(env('APP_URL').route('homes',null,false));
        } else {
            abort(404, '未找到用户名为 '.$user_id.' 的用户。');
        }
    }

    /**
     * 切换移动端用户
     */
    public function mswitchUser($mobile)
    {
        $mobileStudent = MobileStudent::where('mobile', $mobile)->first();
        if($mobileStudent){
//            Student::where('cid', $mobileStudent->cid)->update(['avatar' => $userinfo['imagePath']]);
            $student = Student::where('cid', $mobileStudent->cid)->first();
            Auth::guard('mobile')->login($student);
            return view('mobile.index');
        }else{
            return view('mobile.bind')->with('mobile',$mobile)->with('avatar','');
        }
    }

    /**
     * 切换PC学生端用户
     */
    public function stswitchUser($mobile)
    {
        $mobileStudent = MobileStudent::where('mobile', $mobile)->first();
        if($mobileStudent){
//            Student::where('cid', $mobileStudent->cid)->update(['avatar' => $userinfo['imagePath']]);
            $student = Student::where('cid', $mobileStudent->cid)->first();
            Auth::guard('mobile')->login($student);
            return redirect(route('pc-student.index'));
        }else{
            echo '用户不存在';
        }
    }
}
